
'use strict';

angular.module('myApp.students_file', ['angularFileUpload'])

.controller('students_fileCtrl', ['$scope','$upload','$http', function($scope,$upload,$http) {
	    $scope.$watch('files', function () {
	        $scope.upload($scope.files);
	    });

	    $scope.upload = function (files) {
	        if (files && files.length) {
	            for (var i = 0; i < files.length; i++) {
	                var file = files[i];
	                $upload.upload({
	                    url: 'v1/student_upload_file',
	                    fields: {'id': '123'},
	                    file: file,
	                    data: file,
	                    method: 'POST',
	                    fileFormDataName:"myfile",
	                    headers: {'Content-Type': file.type}
	                }).progress(function (evt) {
	                    var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
	                    console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name);
	                }).success(function (data, status, headers, config) {
	                	console.log(data);
	                    console.log('file ' + config.file.name + 'uploaded. Response: ' + data);
	                });
	            }
	        }
	    };

}]);